package com.qls.consumer.biz.config;

import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author doyoung
 */
@Configuration
public class RabbitListenerConfigBasic {

    /**
     * 酒店初始化
     *
     * @param configurer        SimpleRabbitListenerContainerFactoryConfigurer
     * @param connectionFactory ConnectionFactory
     * @return SimpleRabbitListenerContainerFactory
     */
    @Bean("initContainerFactory")
    public SimpleRabbitListenerContainerFactory initContainerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                                     ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConcurrentConsumers(1);
        factory.setPrefetchCount(1);
        factory.setMaxConcurrentConsumers(2);
        configurer.configure(factory, connectionFactory);
        return factory;
    }

    @Bean("callbackRates")
    public SimpleRabbitListenerContainerFactory callbackRatesContainerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                                              ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConcurrentConsumers(70);
        factory.setPrefetchCount(1);
        factory.setMaxConcurrentConsumers(100);
        configurer.configure(factory, connectionFactory);
        return factory;
    }

    @Bean("callbackRp")
    public SimpleRabbitListenerContainerFactory callbackRpContainerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                                           ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConcurrentConsumers(5);
        factory.setPrefetchCount(1);
        factory.setMaxConcurrentConsumers(10);
        configurer.configure(factory, connectionFactory);
        return factory;
    }

    @Bean("callbackHotel")
    public SimpleRabbitListenerContainerFactory callbackHotelContainerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                                              ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConcurrentConsumers(5);
        factory.setPrefetchCount(1);
        factory.setMaxConcurrentConsumers(10);
        configurer.configure(factory, connectionFactory);
        return factory;
    }

}
